import json

import execjs
import requests

# https://www.ccprec.com/navCqzr/#/cqzr

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'text/xml;charset=UTF-8',
    'Origin': 'https://www.ccprec.com',
    'Pragma': 'no-cache',
    'Referer': 'https://www.ccprec.com/navCqzr/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
    'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}


def honsanCloudAct(page, size=20):
    js = execjs.compile(open('main.js', 'r', encoding="utf-8").read())
    uuid = js.call('uuid')
    data = {"id": uuid,
            "projectKey": "honsan_cloud_ccprec",
            "clientKey": "rtme3kc2en476y0h",
            "token": "",
            "clientDailyData": {},
            "acts": [
                {"id": "rtme4iihcpcyaorm",
                 "fullPath": "/ccprec.com.cn.web/client/info/cqweb_nonphy_cqzr",
                 "args": [
                     page,
                     size
                 ]
                 }
            ]
            }

    data = js.call('encodeData', json.dumps(data))
    response = requests.post('https://www.ccprec.com/honsanCloudAct', headers=headers, data=data)
    data = js.call('decodeData', response.text)
    # for it in data['results'][0]['args'][0]['list']:
    #     print(it)
    print(data)


# https://www.ccprec.com/honsanFileCatch/ccprec.com.cn.web/client/info/cqweb_nonphy_cqzr/desc/content/201612/07/19805-1481095789000-.html

if __name__ == '__main__':
    for i in range(6):
        honsanCloudAct(i + 1)